package com.android.likeweixin.dialog;

import java.io.File;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import com.android.likeweixin.LikeWeixinApp;
import com.android.likeweixin.R;
import com.android.likeweixin.util.StorageUtils;

public class PicSelectDialog extends Dialog implements android.view.View.OnClickListener
{
    public String getCameraPicPath()
    {
        return cameraPicPath;
    }

    public void setCameraPicPath(String cameraPicPath)
    {
        this.cameraPicPath = cameraPicPath;
    }

    public static final int CAMERA_SUCCESS = 0;
    public static final int PHOTO_SUCCESS = 1;
    
    private TextView tv_title;
    
    private TextView capture;
    
    private TextView album;
    
    private Activity context;
    
    /**拍照相片路径*/
    private String cameraPicPath;
    
    public PicSelectDialog(Activity context, int theme)
    {
        super(context, theme);
        this.context = context;
    }
    
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
        setContentView(R.layout.friend_dialog);
        tv_title = (TextView)findViewById(R.id.title);
        capture = (TextView)findViewById(R.id.doCapture);
        album = (TextView)findViewById(R.id.album);
        // 设置标题名称
        tv_title.setText("分享");
        capture.setOnClickListener(this);
        album.setOnClickListener(this);
    }
    
    @Override
    public void onClick(View v)
    {
    	dismiss();
        Intent intent;
        switch (v.getId())
        {
            case R.id.doCapture:
                intent = new Intent("android.media.action.IMAGE_CAPTURE");
                File file = StorageUtils.getCacheDirectory(LikeWeixinApp.getInstance());
                file = new File(file.getPath(), System.currentTimeMillis() + ".jpg");
                cameraPicPath = file.getPath();
                intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
                context.startActivityForResult(intent, CAMERA_SUCCESS);
                break;
            case R.id.album:
                intent = new Intent();
                intent.setAction(Intent.ACTION_GET_CONTENT);
                intent.addCategory(Intent.CATEGORY_OPENABLE);  
                intent.setType("image/*");
                context.startActivityForResult(intent, PHOTO_SUCCESS);
                break;
            
            default:
                break;
        }
    }
}
